﻿<template>
  <div class="l-rblock l-form-viewer" style="padding: 8px">
    <el-form
      :model="formData"
      :rules="rules"
      size="mini"
      labelPosition="right"
      labelWidth="80px"
      ref="form"
    >
      <div class="l-auto-window only-tabs">
        <el-tabs v-model="activeName" type="card">
          <el-tab-pane
            class="l-tabs-container"
            :label="$t('主表信息')"
            name="tab0"
          >
            <el-row :gutter="0">
              <div class="l-rblock">
                <el-col
                  v-if="
                    lr_formLookAuth('case_erp_deviceinspect_f_DeviceNumber')
                  "
                  :span="24"
                >
                  <el-form-item
                    :label="$t('设备编号')"
                    prop="case_erp_deviceinspect_f_DeviceNumber"
                  >
                    <l-layer-select
                      :disabled="
                        !lr_formEditAuth(
                          'case_erp_deviceinspect_f_DeviceNumber',
                          false || isReadOnly
                        )
                      "
                      :isPage="true"
                      :height="504"
                      :width="960"
                      :columns="[
                        {
                          label: '设备编号',
                          prop: 'f_number',
                          valueKey: '',
                          minWidth: 120,
                          align: 'left',
                          hidden: false,
                        },
                        {
                          label: '设备名称',
                          prop: 'f_name',
                          valueKey: '',
                          minWidth: 150,
                          align: 'left',
                          hidden: false,
                        },
                        {
                          label: '设备类型',
                          prop: 'f_type',
                          valueKey: '',
                          minWidth: 100,
                          align: 'left',
                          hidden: false,
                        },
                        {
                          label: '规格型号',
                          prop: 'f_model',
                          valueKey: '',
                          minWidth: 100,
                          align: 'left',
                          hidden: false,
                        },
                        {
                          label: '巡检人',
                          prop: 'f_principal',
                          valueKey: '',
                          minWidth: 100,
                          align: 'left',
                          hidden: false,
                          dataType: 'user',
                        },
                      ]"
                      :options="case_erp_deviceinspect_f_DeviceNumberOptions"
                      v-model="formData.case_erp_deviceinspect_f_DeviceNumber"
                      @change="case_erp_deviceinspect_f_DeviceNumber_change"
                    />
                  </el-form-item>
                </el-col>

                <el-col
                  v-if="lr_formLookAuth('case_erp_deviceinspect_f_Type')"
                  :span="24"
                >
                  <el-form-item
                    :label="$t('设备类型')"
                    prop="case_erp_deviceinspect_f_Type"
                  >
                    <l-select
                      :disabled="true"
                      :options="lr_dataItem['DeviceType']"
                      labelKey="f_ItemName"
                      valueKey="f_ItemValue"
                      v-model="formData.case_erp_deviceinspect_f_Type"
                    />
                  </el-form-item>
                </el-col>

                <el-col
                  v-if="lr_formLookAuth('case_erp_deviceinspect_f_Name')"
                  :span="24"
                >
                  <el-form-item
                    :label="$t('设备名称')"
                    prop="case_erp_deviceinspect_f_Name"
                  >
                    <el-input
                      :disabled="true"
                      v-model="formData.case_erp_deviceinspect_f_Name"
                      :placeholder="$t('请输入')"
                    >
                    </el-input>
                  </el-form-item>
                </el-col>

                <el-col
                  v-if="lr_formLookAuth('case_erp_deviceinspect_f_Model')"
                  :span="24"
                >
                  <el-form-item
                    :label="$t('规格型号')"
                    prop="case_erp_deviceinspect_f_Model"
                  >
                    <el-input
                      :disabled="true"
                      v-model="formData.case_erp_deviceinspect_f_Model"
                      :placeholder="$t('请输入')"
                    >
                    </el-input>
                  </el-form-item>
                </el-col>

                <el-col
                  v-if="lr_formLookAuth('case_erp_deviceinspect_f_UserId')"
                  :span="24"
                >
                  <el-form-item
                    :label="$t('巡检人')"
                    prop="case_erp_deviceinspect_f_UserId"
                  >
                    <l-user-select
                      :disabled="true"
                      v-model="formData.case_erp_deviceinspect_f_UserId"
                    />
                  </el-form-item>
                </el-col>

                <el-col
                  v-if="lr_formLookAuth('case_erp_deviceinspect_f_Date')"
                  :span="24"
                >
                  <el-form-item
                    :label="$t('巡检时间')"
                    prop="case_erp_deviceinspect_f_Date"
                  >
                    <l-date
                      :disabled="
                        !lr_formEditAuth(
                          'case_erp_deviceinspect_f_Date',
                          isReadOnly
                        )
                      "
                      :readonly="false"
                      format="yyyy-MM-dd"
                      dateType="date"
                      :clearable="true"
                      v-model="formData.case_erp_deviceinspect_f_Date"
                      :placeholder="$t('请选择')"
                    />
                  </el-form-item>
                </el-col>

                <el-col :span="24">
                  <el-divider class="myDivider"></el-divider>
                </el-col>

                <el-col
                  v-if="lr_formLookAuth('case_erp_deviceinspect_f_Nature')"
                  :span="24"
                >
                  <el-form-item
                    :label="$t('检查性质')"
                    prop="case_erp_deviceinspect_f_Nature"
                  >
                    <l-select
                      :disabled="
                        !lr_formEditAuth(
                          'case_erp_deviceinspect_f_Nature',
                          false || isReadOnly
                        )
                      "
                      :options="lr_dataItem['Nature']"
                      labelKey="f_ItemName"
                      valueKey="f_ItemValue"
                      v-model="formData.case_erp_deviceinspect_f_Nature"
                    />
                  </el-form-item>
                </el-col>

                <el-col
                  v-if="lr_formLookAuth('case_erp_deviceinspect_f_Result')"
                  :span="24"
                >
                  <el-form-item
                    :label="$t('检查结果')"
                    prop="case_erp_deviceinspect_f_Result"
                  >
                    <el-input
                      :disabled="
                        !lr_formEditAuth(
                          'case_erp_deviceinspect_f_Result',
                          false || isReadOnly
                        )
                      "
                      type="textarea"
                      v-model="formData.case_erp_deviceinspect_f_Result"
                      :rows="4"
                      placeholder="请输入内容"
                    >
                    </el-input>
                  </el-form-item>
                </el-col>

                <el-col
                  v-if="lr_formLookAuth('case_erp_deviceinspect_f_File')"
                  :span="24"
                >
                  <el-form-item
                    :label="$t('上传附件')"
                    prop="case_erp_deviceinspect_f_File"
                  >
                    <l-upload
                      listType="picture-card"
                      :disabled="
                        !lr_formEditAuth(
                          'case_erp_deviceinspect_f_File',
                          false || isReadOnly
                        )
                      "
                      v-model="formData.case_erp_deviceinspect_f_File"
                    >
                    </l-upload>
                  </el-form-item>
                </el-col>

                <el-col
                  v-if="lr_formLookAuth('case_erp_deviceinspect_f_State')"
                  :span="24"
                >
                  <el-form-item
                    :label="$t('选择状态')"
                    prop="case_erp_deviceinspect_f_State"
                  >
                    <el-radio-group
                      v-model="formData.case_erp_deviceinspect_f_State"
                    >
                      <el-radio :label="0">{{ $t("通过") }}</el-radio>
                      <el-radio :label="1">{{ $t("不通过") }}</el-radio>
                    </el-radio-group>
                  </el-form-item>
                </el-col>
              </div>
            </el-row>
          </el-tab-pane>
        </el-tabs>
      </div>
    </el-form>
  </div>
</template>
<script>
const api = window.$api.erpcase.deviceInspect;
export default {
  props: {
    isReadOnly: {
      type: Boolean,
      default: false,
    },
  },
  data() {
    return {
      moduleCode: "ERP_DeviceInspect",
      activeName: "tab0",
      formData: {
        case_erp_deviceinspect_f_Type: "", // 设备类型
        case_erp_deviceinspect_f_DeviceNumber: "", // 设备编号
        case_erp_deviceinspect_f_Name: "", // 设备名称
        case_erp_deviceinspect_f_Model: "", // 规格型号
        case_erp_deviceinspect_f_UserId: "", // 巡检人
        case_erp_deviceinspect_f_Date: "", // 巡检日期
        case_erp_deviceinspect_f_Nature: "", // 检查性质
        case_erp_deviceinspect_f_Result: "", // 检查结果
        case_erp_deviceinspect_f_File: "", // 上传附件
        case_erp_deviceinspect_f_State: 0, // 选择状态
        case_erp_deviceinspect_f_Address: "", // 设备位置
      },
      rules: {
        case_erp_deviceinspect_f_DeviceNumber: [
          { required: true, message: "请选择设备编号" },
        ],
        case_erp_deviceinspect_f_Date: [
          { required: true, message: "请选择巡检时间" },
        ],
      },
    };
  },
  computed: {
    case_erp_deviceinspect_f_DeviceNumberOptions() {
      const data = this.lr_DataSource("ERP_Devices");
      return this.lr_DataSourceOptions(data, "f_number", "f_number");
    },
  },

  mounted() {
    this.systemDATAItem();
  },

  methods: {
    case_erp_deviceinspect_f_DeviceNumber_change(changeData) {
      if (changeData) {
        this.$set(
          this.formData,
          "case_erp_deviceinspect_f_Type",
          changeData.f_type
        );
      } else {
        this.$set(this.formData, "case_erp_deviceinspect_f_Type", undefined);
      }
      if (changeData) {
        this.$set(
          this.formData,
          "case_erp_deviceinspect_f_Name",
          changeData.f_name
        );
      } else {
        this.$set(this.formData, "case_erp_deviceinspect_f_Name", undefined);
      }
      if (changeData) {
        this.$set(
          this.formData,
          "case_erp_deviceinspect_f_Model",
          changeData.f_model
        );
      } else {
        this.$set(this.formData, "case_erp_deviceinspect_f_Model", undefined);
      }
      if (changeData) {
        this.$set(
          this.formData,
          "case_erp_deviceinspect_f_UserId",
          changeData.f_principal
        );
      } else {
        this.$set(this.formData, "case_erp_deviceinspect_f_UserId", undefined);
      }
    },

    // 数据字典
    systemDATAItem() {
      this.lr_loadDataItem("DeviceType"); // 设备类型
      this.lr_loadDataItem("Nature"); // 巡检性质
    },

    // 重置表单
    resetForm() {
      this.formData.case_erp_deviceinspect_f_Id = '';
      this.$formClear(this.$refs.form);
      this.activeName = "tab0";
    },
    // 校验表单
    async validateForm() {
      if (!(await this.$formValidateWraper(this.$refs.form))) {
        return false;
      }

      return true;
    },
    // 设置表单数据
    setForm(data) {
      this.$setFormData(this.formData, data, "case_erp_deviceinspect");
    },
    // 获取表单数据
    getForm() {
      return this.$getFormData(this.formData, "case_erp_deviceinspect");
    },

    async loadFormData({ keyValue /*,params,node*/ }) {
      //  keyValue 流程中相当于流程processId,params 传递参数,node 流程节点
      const data = await this.$awaitWraper(api.get(keyValue));
      if (data) {
        this.setForm(data);
        return true;
      } else {
        return false;
      }
    },

    async saveForm({ keyValue, isEdit /*,code,node*/ }) {
      // isEdit 是否更新数据, keyValue 流程中相当于流程processId,code 表示流程中的操作码,node 流程节点
      const postData = this.getForm();
      if (isEdit) {
        // 编辑
        return await this.$awaitWraper(api.update(keyValue, postData));
      } else {
        // 新增
        postData.f_Id = keyValue;

        return await this.$awaitWraper(api.add(postData));
      }
    },
  },
};
</script>

<style lang="scss">
.el-divider--horizontal.myDivider {
  margin: 0px;
  margin-bottom: 16px;
}
</style>